﻿using Microsoft.AspNetCore.Mvc;
using SimpleORM.Service.IService;
using SimpleORM.Service.Service;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace SimpleORM.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class GenerateoneController : ControllerBase
    {
        private readonly IGenerateoneService  generateoneService;
        private readonly IGeneratetwoService generatetwoService ;

        public GenerateoneController(IGenerateoneService _generateoneService, IGeneratetwoService _generatetwoService)
        {
            generateoneService = _generateoneService;
            generatetwoService = _generatetwoService;

        }

        /// <summary>
        /// 生成实体
        /// </summary>
        /// <param name="tablenames">多表用，隔开；整个库生成，不填写；basecode 0代表主库，其他自选，默认主库</param>
        /// <param name="basecode"></param>
        /// <returns></returns>
        [HttpPost(Name = "GetModel")]
        public ActionResult GetModel(string ? tablenames,int ?basecode=0)
        {
            string[] result = tablenames.Split(',');
            bool outcode=false;
            if(basecode==0)
            {
                if (result.Length == 0)
                {
                    outcode = generateoneService.GenerateDataBaseModel();
                }
                else
                {
                    outcode=generateoneService.GenerateListTableModel(result);
                }

            }
            else
            {
                if (result.Length == 0)
                {
                    outcode = generatetwoService.GenerateDataBaseModel();
                }
                else
                {
                    outcode = generatetwoService.GenerateListTableModel(result);

                }

            }

            return Ok(outcode);
        }
    }
}
